package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark80Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark80 extends BaseMark {

    LayoutWatermark80Binding binding;

    public Mark80(@NonNull Context context) {
        super(context);
    }

    public Mark80(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark80(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark80Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.mid.getChildCount();
            for (int i = 2; i < n; i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark80Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    private void setTime() {
        setTime(binding.binding3, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
    }

    @Override
    public void update() {
        setText(binding.binding1, "title80", binding.binding1);
        setText(binding.binding3, "time80", binding.binding2);
        setTime();

        setText(binding.binding5, "area80", binding.binding4);
        setText(binding.binding7, "person80", binding.binding6);
        setText(binding.binding9, "result80", binding.binding8);
        setText(binding.binding11, "didian80", binding.binding10);
        setText(binding.binding13, "beizhu80", binding.binding12);
        setText(binding.binding15, "tip80", binding.binding4);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title80", "标题"));
        list.add(new EditItem("time80", "时间", true));
        list.add(new EditItem("area80", "巡逻区域"));
        list.add(new EditItem("person80", "巡逻人员"));
        list.add(new EditItem("result80", "巡逻结果"));

        list.add(new EditItem("didian80", "地址"));
        list.add(new EditItem("beizhu80", "备注"));

        list.add(new EditItem("tip80", "提示语"));


        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime();
        } else {
            super.onValueChange(item);
        }
    }
}
